package cn.example.smartagriculture.slice;

import cn.example.smartagriculture.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TabList;

import java.util.ArrayList;
import java.util.List;

public class MainAbilitySlice extends AbilitySlice {

    private List<TabList.Tab> tabs;
    private String TAG = "智慧农业";
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initTabList();
    }

    private void initTabList() {
        tabs = new ArrayList<TabList.Tab>();
        TabList tabList = (TabList) findComponentById(ResourceTable.Id_tltNav);

        TabList.Tab tabAir = tabList.new Tab(getContext());
        tabAir.setText(ResourceTable.String_strPgAir);
        tabList.addTab(tabAir);

        TabList.Tab tabSoil = tabList.new Tab(getContext());
        tabSoil.setText(ResourceTable.String_strPgSoil);
        tabList.addTab(tabSoil);

        TabList.Tab tabControl = tabList.new Tab(getContext());
        tabControl.setText(ResourceTable.String_strPgControl);
        tabList.addTab(tabControl);

        TabList.Tab tabMe = tabList.new Tab(getContext());
        tabMe.setText(ResourceTable.String_strPgMe);
        tabList.addTab(tabMe);

        tabAir.select();
        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
                int i = tab.getPosition();
                System.out.println(TAG + "这是第" + i + "个tab");
                System.out.println(TAG + "Tab:" + tab.getText());
            }

            @Override
            public void onUnselected(TabList.Tab tab) {

            }

            @Override
            public void onReselected(TabList.Tab tab) {

            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
